import type { PutRes, DisableDto, DisableRes } from "~/rest";

import { getGateway } from "@/droplet-bus/core.define";
import { Gateway } from "@/droplet-bus/core.define";

import { app_gateway } from "./core.local";
import { AccessAll } from "./core.define";
import { Access } from "./schema.access";

export const AccessGateway: Gateway = getGateway(app_gateway, "stream_access");
export type putAccessDto = Pick<Access, "id" | "droit">;
export type deleteAccessDto = DisableDto & {
  /** 顺便删除这个访客的全部授权 */
  isClear?: boolean;
};

export interface AccessInterfaceWithPrimary<T> {
  /** 管理员修改某个授权的具体内容（增删改查导）*/
  putAccess(dto: T & putAccessDto): Promise<PutRes<Access>>;
  /** 管理员物理删除某个授权 */
  deleteAccess(dto: T & deleteAccessDto): Promise<DisableRes>;
}

export type searchAccessDto = { scope?: string };
export type getAccessDroitContextDto = Pick<Access, "scope" | "refVisitorId">;

export interface AccessInterfaceWithDerive<T> {
  /** 返回和访客有关系的全部授权（授权别人/被授权）*/
  search(dto: T & searchAccessDto): Promise<AccessAll>;
  /** 根据资源链接查询具体授权 */
  getAccessDroitContext(dto: T & getAccessDroitContextDto): Promise<{ entity?: Access }>;
}
